﻿/**********************************************************
 ●项目：Smartkernel
 ●公司：智能核心信息技术研发中心
 ●作者：曹艳白
 ●邮箱：caoyanbai@gmail.com
 ●创建：2008-08-10
**********************************************************/
using System;
using System.Management;
using Microsoft.VisualBasic.Devices;

namespace Smartkernel
{
    /// <summary>
    /// 主机相关功能的集合
    /// </summary>
    public static class SmartLocalHost
    {
        /// <summary>
        /// 计算机名
        /// </summary>
        public static string ComputerName
        {
            get
            {
                return Environment.GetEnvironmentVariable("ComputerName");
            }
        }
        /// <summary>
        /// 当前登录的用户名
        /// </summary>
        public static string UserName
        {
            get
            {
                return Environment.GetEnvironmentVariable("UserName");
            }
        }
        private static Computer computer = new Computer();
        /// <summary>
        /// 获得当前计算机的各种信息简便操作对象（同于VB中的My功能）
        /// </summary>
        public static Computer Computer
        {
            get
            {
                return computer;
            }
        }
        /// <summary>
        /// 获得信息已经运行的时间
        /// </summary>
        public static TimeSpan RunTime
        {
            get
            {
                return TimeSpan.FromMilliseconds(Environment.TickCount);
            }
        }
        /// <summary>
        /// 获得CPU的个数
        /// </summary>
        public static int CPUCount
        {
            get
            {
                ManagementObjectSearcher search = new ManagementObjectSearcher("SELECT * FROM Win32_Processor");
                return search.Get().Count;
            }
        }
    }
}
